package apis

import (
	"ckeadm/cmd/apis/v1alpha1"
	"k8s.io/apimachinery/pkg/runtime/schema"
)

type CkeAdmKubernetesConfig struct {
	ClusterName       string             `yaml:"cluster_id,omitempty"`
	Version           string             `yaml:"version,omitempty"`
	ClusterParameters CkeClusterPrameter `yaml:"cluster_parameters,omitempty"`
	Registry          CkeRegistry        `yaml:"registry,omitempty"`
	// deprecated, use cluster_vip replace
	ClusterVips       []CkeClusterVip         `yaml:"-"`
	ClusterVip        CkeClusterVip           `yaml:"-"`
	Etcd              CkeEtcd                 `yaml:"etcd,omitempty"`
	Docker            CkeDocker               `yaml:"docker,omitempty"`
	Dns               CkeDns                  `yaml:"coredns,omitempty"`
	Plugins           []CkeAddons             `yaml:"storage,omitempty"`
	Addons            []CkeAddons             `yaml:"addons,omitempty"`
	ExtraArgs         map[string]string       `yaml:"extra_args,omitempty"`
	DockerPreconfiged []string                `yaml:"docker_preconfiged" json:"docker_preconfiged"`
	AnsibleSshPort    int                     `yaml:"ansible_ssh_port,omitempty"`
	Components        []v1alpha1.CkeComponent `yaml:"components,omitempty"`

	// external
	Nodes       []CkeConfigNode `yaml:"nodes,omitempty"`
	Calico      CkeCalico       `yaml:"calico,omitempty"`
	WatchConfig *WatchConfig    `yaml:"-"`
}

type CkeConfigNode struct {
	Address     string            `yaml:"address,omitempty"`
	Name        string            `yaml:"name,omitempty"`
	Roles       []string          `yaml:"roles,omitempty"`
	Labels      []string          `yaml:"labels,omitempty"`
	Taints      []string          `yaml:"taints,omitempty"`
	MaxPods     int               `yaml:"max_pods,omitempty"`
	Annotations map[string]string `yaml:"annotations,omitempty"`
}

type CkeClusterPrameter struct {
	KubeServiceCidr        string `yaml:"kube_service_addresses_use,omitempty"`
	KubePodsCidr           string `yaml:"kube_pods_subnet_use,omitempty"`
	DefaultMasterMaxPods   int    `yaml:"master_max_pods,omitempty"`
	DefaultSlaveMaxPods    int    `yaml:"slave_max_pods,omitempty"`
	ClusterSize            int    `yaml:"cluster_size,omitempty"`
	ApiserverDomainName    string `yaml:"apiserver_loadbalancer_domain_name,omitempty"`
	KubeletDataRoot        string `yaml:"kubelet_data_root,omitempty"`
	OverrideSystemHostname bool   `yaml:"override_system_hostname"`
	ImageManifestEnabled   bool   `yaml:"harbor_manifest_enabled"`
	OidcIssuerUrl          string `yaml:"keycloak_url,omitempty"`
	KubeProxyMode          string `yaml:"kube_proxy_mode,omitempty"`
	// deprecated, use ntp_servers replace
	ExternalNtpServer []string `yaml:"-"`
	NtpServers        []string `yaml:"external_ntp_server,omitempty"`
}

type CkeRegistry struct {
	Ip     string `yaml:"registry_ip,omitempty"`
	Port   int    `yaml:"registry_port,omitempty"`
	Domain string `yaml:"registry_domain,omitempty"`
}

type CkeClusterVip struct {
	Ip          string `yaml:"vip,omitempty"`
	RouterId    int    `yaml:"router_id,omitempty"`
	Interface   string `yaml:"interface,omitempty"`
	IsApiserver bool   `yaml:"is_master_vip,omitempty"`
}

type CkeDns struct {
	Type  string                 `yaml:"type,omitempty"`
	Hosts []CkeExternalDnsDomain `yaml:"external_dns_domain,omitempty"`
	// deprecated, use external_servers replace
	ExternalDns     []string `yaml:"-"`
	ExternalServers []string `yaml:"external_dns,omitempty"`
}

type CkeExternalDnsDomain struct {
	Ip   string   `yaml:"ip,omitempty"`
	Name []string `yaml:"name,omitempty"`
}

type CkeEtcd struct {
	HeartbeatInterval int `yaml:"etcd_heartbeat_interval,omitempty"`
	ElectionTimeout   int `yaml:"etcd_election_timeout,omitempty"`
}

type CkeDocker struct {
	DockerDataRoot string   `yaml:"docker_data_root,omitempty"`
	Registries     []string `yaml:"-"`
}

type CkeCalico struct {
	Mtu int `yaml:"calico_mtu,omitempty"`
}

//// use by translate
type CkeAddons struct {
	Name       string            `yaml:"name,omitempty"`
	Parameters map[string]string `yaml:"parameters,omitempty"`
}

type AllLabel struct {
	Detail  string   `yaml:"detail,omitempty"`
	Members []string `yaml:"members,omitempty"`
	Taint   string   `yaml:"taint,omitempty"`
}

type AllClusterVip struct {
	MasterVip       string          `yaml:"master_vip,omitempty"`
	VipInterface    string          `yaml:"vip_interface,omitempty"`
	VirtualRouterId int             `yaml:"virtual_router_id,omitempty"`
	VipList         []CkeClusterVip `yaml:"vip_list,omitempty"`
}

type LBApiserver struct {
	Address string `yaml:"address,omitempty"`
	Port    string `yaml:"port,omitempty"`
}

type InstallInfo struct {
	Name     string
	Status   string
	Progress string
	Message  string
}

type LogContext struct {
	ClusterID string
	NodeName  string
	DoneFile  string
	DoneInfo  string
}

type ComponentLog struct {
	ClusterID     string
	NodeName      string
	ComponentName string
	TimeStamp     string
	LogContent    string
	LogId         int
	Suffix        string
	Action        string
}

type ComponentListInfo struct {
	Name          string
	Version       string
	BaseComponent string
	Depend        string
}

type InstallStatusInfo struct {
	Name     string
	Status   string
	Progress string
	Message  string
}

type WatchConfig struct {
	ListenPort    int
	ListenAddress string
	CluserID      string
	ConfigPath    string
	LogCacheDir   string
}

type AnsibleDockerPerms struct {
	ContainerName string
	ImageName     string
	PrivateKey    string
	InvFilePath   string
	AllFilePath   string
	SourcesPath   string
	ExecerPatch   string
}

type GVKContent struct {
	GVK     schema.GroupVersionKind
	Content []byte
}

type GvkSlice []GVKContent

type LogRoutineParam struct {
	ComponentLogArray []ComponentLog
	AddressArray      []string
	KeyFile           string
	Time              string
}
